
import axios from  'axios'
import * as constants from './constants'
import {fromJS } from 'immutable'
const changeHomeData = (data)=>({
    type:constants.CHANGE_HOME_DATA,
    topicList:data.topicList,
    articleList:data.articleList,
    recommedList:data.recommedList
})

const addHomeList = (list,nextPage)=>({
    type:constants.ADD_HOME_LIST,
    list:fromJS(list),
    nextPage:nextPage
});
export const getHomeInfo =()=>{
    return (dispatch)=>{
        axios.get('/api/homeData.json').then((res)=>{
            const {data} = res;
            console.log(data)
            const action = changeHomeData(data);
            dispatch(action);
        });
    }
};


export const getMove=(page)=>{
    return (dispatch)=>{
        axios.get('/api/list.json?page='+page).then((res)=>{
            const {list} = res.data;

            dispatch(addHomeList(list,page+1));
        });
    }
}


export const toggleScroll = (show)=>({
    type:constants.TOGGLE_SCROLL,
    show:show
})


